package com.cloudm.technician.ui.modules.cloudm_box.transfer

import android.view.View
import android.view.ViewGroup
import com.cloudm.technician.R
import com.cloudm.technician.data.model.SearchInfo
import com.cloudm.technician.extensions.inflate
import com.cloudm.technician.extensions.loadImage
import com.cloudm.technician.ui.base.BaseAdapter
import com.cloudm.technician.ui.base.BaseViewHolder
import com.cloudm.technician.ui.widget.OnceClickListener
import kotlinx.android.synthetic.main.item_transfer.view.*

/**
 * 作者: wesley
 * 时间: 2017/12/24
 * 描述: 适配器
 */
class TransferAdapter : BaseAdapter<SearchInfo>() {

    var listener: OnTransferClickListener? = null

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): BaseViewHolder<SearchInfo> {
        return ItemViewHolder(parent?.inflate(R.layout.item_transfer))
    }

    inner class ItemViewHolder(itemView: View?) : BaseViewHolder<SearchInfo>(itemView) {
        override fun onBind(t: SearchInfo) {
            itemView.item_icon.loadImage(t.middlelogo, R.mipmap.ic_login_user_icon)
            itemView.item_name.text = t.name
            itemView.item_phone.text = t.mobi

            itemView.item_transfer.setOnClickListener(object : OnceClickListener() {
                override fun onOnceClick(view: View) {
                    listener?.onTransferClick(t)
                }
            })
        }
    }


    interface OnTransferClickListener {
        fun onTransferClick(searchInfo: SearchInfo)
    }
}